#pragma once

#include <struct/query_context.hpp>
#include <data/sql/sql_expr.hpp>
#include <serialization/writer_options.hpp>
#include <data/data_result.hpp>

namespace blitz_query_cpp
{
    template <class WriterT>
    class serialize_result
    {
    public:
        bool process(query_context &context)
        {
            writer_options_t options;
            options.format = true;
            WriterT writer{options};
            if (context.objects.contains("data_result"))
            {
                data_result_t &result = std::any_cast<data_result_t &>(context.objects["data_result"]);
                result.serialize(writer);
                context.data.emplace("result_str", std::move(writer.get_string()));
            }
            return true;
        }
    };
}
